package com.tourism.website.comment.controller;


import com.tourism.website.apis.CommentApis;
import com.tourism.website.comment.service.ICommentService;
import com.tourismwebsite.comment.dto.CommentDTO;
import com.tourismwebsite.comment.query.CommentQuery;
import com.tourismwebsite.vo.JsonVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lyc
 * @since 2024-06-13
 */
@RestController
@RequestMapping("/comment")
@Validated
@Api(tags = "评论信息管理")
public class CommentController implements CommentApis {
    @Resource
    ICommentService commentService;

    @GetMapping("/query-comments")
    @ApiOperation(value = "查询评论信息")
    @Override
    public JsonVO<List<CommentDTO>> queryNotDelComments(@Validated CommentQuery commentQuery) {
        List<CommentDTO> commentDTOS = commentService.queryNotDelComments(commentQuery);
        return JsonVO.success(commentDTOS);
    }

    @PostMapping("/save-comment")
    @ApiOperation(value = "添加评论")
    @Override
    public JsonVO<Boolean> saveComment(@Validated CommentQuery commentQuery) {
        Boolean result = commentService.saveComment(commentQuery);
        if (result) return JsonVO.success(result);
        return JsonVO.create(result, 9999, "添加失败");
    }

    @DeleteMapping("/delete-comment")
    @ApiOperation(value = "删除评论")
    @Override
    public JsonVO<Boolean> deleteComment(@Validated CommentQuery commentQuery) {
        Boolean result = commentService.deleteComment(commentQuery);
        if (result) return JsonVO.success(result);
        return JsonVO.create(result, 9999, "评论不存在或已被删除");
    }
}

